package com.ajieee.merge.entity.common.result;

import com.ajieee.merge.enums.common.ResultCode;
import lombok.Data;

/**
 * @author ajieee
 * @date 2025-10-25
 */
@Data
public class ApiResult<T> {

	private int code;

	private String message;

	private T data;

	private long timestamp;

	public static <T> ApiResult<T> success() {
		return success(null);
	}

	public static <T> ApiResult<T> success(T data) {
		return success(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
	}

	public static <T> ApiResult<T> success(int code, String message, T data) {
		ApiResult<T> result = new ApiResult<>();
		result.setCode(code);
		result.setMessage(message);
		result.setData(data);
		result.setTimestamp(System.currentTimeMillis());
		return result;
	}

	public static ApiResult<Void> error(String message) {
		return error(ResultCode.FAILED.getCode(), message);
	}

	public static ApiResult<Void> error(int code, String message) {
		ApiResult<Void> errorResult = new ApiResult<>();
		errorResult.setCode(code);
		errorResult.setMessage(message);
		errorResult.setTimestamp(System.currentTimeMillis());
		return errorResult;
	}
}
